#include<stdio.h>
#include<unistd.h>
#include<signal.h>
void timeout(int sig)
{
	if(sig==SIGALRM)
		puts("Time out!");
	alarm(2);
}
int main(int argc,char *argv[])
{
	int i;
	struct sigaction act;
	//声明sigaction结构体变量并在sa_handler成员中保存函数指针值
	act.sa_handler=timeout;
	//调用sigemptyset函数将sa_mask成员的所有位初始化为0
	sigemptyset(&act.sa_mask);
	act.sa_flags=0;
	//int sigaction(int signo,const struct sigaction *act,struct sigaction *oldact)
	sigaction(SIGALRM,&act,0);
	alarm(2);
	for(i=0;i<3;i++)
	{
		puts("wait...");
		sleep(100);
	}
	return 0;
}
